ifeq ($(yt_srctree),)
yt_srctree := $(patsubst %/,%,$(dir $(CURDIR)))
yt_srctree := $(patsubst %/,%,$(dir $(yt_srctree)))
yt_srctree := $(patsubst %/,%,$(dir $(yt_srctree)))
endif

BPF_BUILF_CONFIG_FILE ?= $(yt_srctree)/hacks/yt_build_bpf_yocto_libbpf_v1.mk
include ${BPF_BUILF_CONFIG_FILE}

BPF_SRCS := helloworld.bpf.c
BPF_LOADER_SRC := loader.c

BPF_HEADERS = $(BPF_SRCS:.bpf.c=.skel.h)
BPF_OBJ = $(BPF_SRCS:.bpf.c=.bpf.o)

BPF_LOADER := loader
# 必须要得加上 -O2 优化等级 
CLANG_BPF_SYS_INCLUDES = $(shell $(CLANG) -v -E - </dev/null 2>&1 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
outfile := $(source:.p4=.json)
${BPF_OBJ}:${BPF_SRCS}
	${CLANG} -target bpf ${CLANGFLAGS} ${CCINCLUDE} $(CLANG_BPF_SYS_INCLUDES) -c ${BPF_SRCS}

${BPF_HEADERS}: ${BPF_OBJ}
	$(BPFTOOL) gen skeleton ${BPF_OBJ} > $@

${BPF_LOADER}: ${BPF_SRCS} ${BPF_HEADERS} ${BPF_LOADER_SRC}
	${CC} $(CCFLAGS) ${LOADINCLUDE} $(CLANG_BPF_SYS_INCLUDES) -o ${BPF_LOADER} ${BPF_LOADER_SRC} ${liba_path}

build: ${BPF_LOADER}

all: clean build push
push:
	adb push ${BPF_LOADER} /data/
	adb shell sync
	adb shell "cd /data && scp ${BPF_LOADER}  root@192.168.100.1:~/"

clean:
	rm -rf *.o *.skel.h helloworld
.DEFAULT_GOAL := all